using System;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;

namespace CodeStream.Testing.WebAutomation
{
    /// <summary>
    /// Represents a container element in the UIDefinition xml file.
    /// </summary>
    public class UIDefinitionClass
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UIDefinitionContainer"/> class.
        /// </summary>
        /// <param name="typeName">The name of the class.</param>
        /// <param name="tag">The HTML tag describing the container.</param>
        /// <param name="id">The optional id used to locate the container in the page under test.</param>
        /// <param name="cssClass">The optional CSS class used to locate the container in the page under test.</param>
        /// <param name="fields">The fields contained within the container.</param>
        internal UIDefinitionClass(string typeName, string tag, string id, string cssClass, ReadOnlyCollection<UIDefinitionField> fields)
        {
            Contract.Requires(!string.IsNullOrEmpty(typeName));
            Contract.Requires(!string.IsNullOrEmpty(tag));
            Contract.Requires(fields != null);

            TypeName = typeName.ToIdentifier();
            Tag = tag;
            Id = id;
            CssClass = cssClass;
            Fields = fields;

            BaseTypeName = tag.ConvertToType().Name;
        }

        /// <summary>
        /// Gets the name of the class that is generated for the container object.
        /// </summary>
        public string TypeName { get; private set; }

        /// <summary>
        /// Gets the name of the base type for the class.  It's based on the HTML tag of the container.
        /// </summary>
        public string BaseTypeName { get; private set; }

        /// <summary>
        /// Gets the HTML tag of the container.
        /// </summary>
        public string Tag { get; private set; }

        /// <summary>
        /// Gets the optional id used to identify the container in the page under test.
        /// </summary>
        public string Id { get; private set; }

        /// <summary>
        /// Gets the optional CSS class used to identify the container in the page under test.
        /// </summary>
        public string CssClass { get; private set; }    
 
        /// <summary>
        /// Get the fields that are contained within this container.
        /// </summary>
        public ReadOnlyCollection<UIDefinitionField> Fields { get; private set; }
    }
}